﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CrayonsBox.Drawing
{
    /// <summary>
    /// Interaction logic for DrawingBox.xaml
    /// </summary>
    public partial class DrawingBox : UserControl
    {
        private Document document;
        private WriteableBitmap canvas;

        public Document Document
        {
            get { return document; }
        }
            
        public DrawingBox()
        {
            InitializeComponent();
            document = new Document(documentHost);
        }

        protected override void OnVisualParentChanged(DependencyObject oldParent)
        {       
            //Do nothing
        }

        protected override void OnRender(DrawingContext drawingContext)
        {
            //Do nothing
        }

        private void border_SizeChanged(object sender, SizeChangedEventArgs e)
        {      
            document.OnSizeChanged((int)e.NewSize.Width, (int)e.NewSize.Height);
            document.OnLoad();
        }

        private void documentHost_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void documentHost_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void documentHost_KeyUp(object sender, KeyEventArgs e)
        {
            document.OnKeyUp(e);
        }

        private void documentHost_MouseDown(object sender, MouseButtonEventArgs e)
        {
            Keyboard.Focus(documentHost);
            document.OnMouseDown(e);
        }

        private void documentHost_MouseMove(object sender, MouseEventArgs e)
        {
            document.OnMouseMove(e);
        }

        private void documentHost_MouseUp(object sender, MouseButtonEventArgs e)
        {
            document.OnMouseUp(e);
        }
    }
}
